package com.shuma.upms.permission.mapper;

import com.shuma.upms.permission.domain.entity.UserRole;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserRoleMapper {


    // 插入用户角色
    @Insert("insert into user_roles(user_id, role_id) values (#{userId}, #{roleId})")
    int insert(UserRole userRole);

    // 根据用户id查询用户角色
    @Select("select * from user_roles where user_id = #{userId}")
    UserRole findByUserId(Long userId);

    // 根据用户id查询用户角色代码
    @Select("select r.role_code from user_roles ur join roles r on ur.role_id = r.role_id where ur.user_id = #{userId}")
    String findRoleCodeByUserId(@Param("userId") Long userId);

    // 根据用户id更新用户角色
    @Update("UPDATE user_roles SET role_id = #{roleId} WHERE user_id = #{userId}")
    int updateRoleIdByUserId(@Param("userId") Long userId, @Param("roleId") Integer roleId);

}